/*
 * @Descripttion: 
 * @version: 
 * @Author: lily
 * @Date: 2021-04-30 14:20:44
 * @LastEditors: lily
 * @LastEditTime: 2021-04-30 14:43:26
 */
/*
 * @lc app=leetcode.cn id=274 lang=javascript
 *
 * [274] H 指数
 */

// @lc code=start
/**
 * @param {number[]} citations
 * @return {number}
 */

//  思路：排序
//  先排序，找出最大的i满足 citations[i] > i

//  复杂度：O(logn) O(logn)

var hIndex = function (citations) {
    let res = 0

    // 倒序排序
    citations.sort((a, b) => b - a)
    // 线性扫描
    for (let i = 0; i < citations.length; i++) {
        if (citations[i] > i) {
            res++
        }
    }
    return res

};
// @lc code=end

console.log(hIndex([3, 0, 6, 1, 5]));
